<template>
  <div class="search">
    <div v-if="title" class="top_title">
      <div class="title">{{ title }}</div>
      <slot name="sub_title"></slot>
    </div>
    <div class="top_search" v-if="showSearchForm">
      <div class="form">
        <slot name="form" />
      </div>
      <div class="searchButtonGroup">
        <div v-if="showSearch" style="margin-bottom: 11px;">
          <EvButton icon="el-icon-search" type="primary" @click="handleQuery">{{ $t("common.common_operation_search") }}</EvButton>
        </div>
        <div v-if="!singleLine">
          <EvButton icon="el-icon-refresh" type="primary" plain @click="resetQuery">{{ $t("common.common_operation_reset") }}</EvButton>
        </div>
      </div>
    </div>
    <div v-if="!singleLine" class="divider_box">
      <div
        style="width: 100%; height: 1px"
        :style="{ marginTop: showSearchForm ? '-20px' : '-6px' }"
      ></div>
      <el-divider @click="collapse">
        <span style="cursor: pointer; color: #6c7079">
          {{ showSearchForm ? $t("common.common_fold_search") : $t("common.common_spread_search") }}
        </span>
        <i
          :class="showSearchForm ? 'el-icon-arrow-up' : 'el-icon-arrow-down'"
        ></i
      ></el-divider>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    title: {
      type: String,
      default: "",
    },
    showSearch: {
      type: Boolean,
      default: true,
    },
    singleLine: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      showSearchForm: true, // 搜索显示与否
    };
  },
  created() {},
  mounted() {},
  methods: {
    // 展开关闭页
    collapse() {
      this.showSearchForm = !this.showSearchForm;
    },
    handleQuery() {
      this.$emit("handleQuery");
    },
    resetQuery() {
      this.$emit("resetQuery");
    },
  },
};
</script>

<style lang="scss" scoped>
.search {
  .top_title {
    .title {
      float: left;
      font-size: 16px;
      font-weight: bold;
      margin-bottom: 8px;
    }
  }
  .top_search {
    width: 100%;
    display: table;
    margin-bottom: 6px;
    .form {
      display: table-cell;
      width: 92%;
    }
    .searchButtonGroup {
      width: 8%;
      display: table-cell;
      text-align: right;
      vertical-align: top;
    }
  }
}
::v-deep .el-divider--horizontal {
  margin: 36px 0 6px 0;
}
::v-deep .el-divider {
  background-color: #e1e6f0;
}
</style>